/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package zeroticket;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.ResultSetMetaData;
import com.mysql.jdbc.Statement;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.imgscalr.Scalr;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
 *
 * @author giovannirojas
 */
public class MainView extends javax.swing.JFrame {

    // FOR CAMERA 
    JMFCamara tphoto = new JMFCamara();
    private Event dataEventList[];
    // Variables de base de datos 
    private Statement st = DataBaseClass.getSt();
    private Connection connection = DataBaseClass.getConnection();
    private ResultSet resultSet = DataBaseClass.getResultSet();

    // Variables que guardare. 
    private int tagID = -1;
    private byte[] photoBytes = null;
    private DPIinfo info = null;
    private int userID = -1;

    private boolean able = false;

    public MainView() {
        initComponents();
        panelsContainer.removeAll();
        panelsContainer.add(mainPanel);
        eventList();
        /*
         try {
         //se coloca un layout tipo CAJA        
         VIDEO.setLayout(new javax.swing.BoxLayout(VIDEO, javax.swing.BoxLayout.LINE_AXIS));
         //se añade el componente de video
         VIDEO.add(tphoto.Componente());
         imagen.setText("");
         } catch (Exception e) {
         JOptionPane.showMessageDialog(rootPane, "Error al cargar CAMARA");
         }*/
    }

    // Va a configurar la aplicación 
    public MainView(String config) {
        initComponents();
        panelsContainer.removeAll();
        panelsContainer.add(configuracionPanel);
        eventList();
        /*
         try {
         //se coloca un layout tipo CAJA        
         VIDEO.setLayout(new javax.swing.BoxLayout(VIDEO, javax.swing.BoxLayout.LINE_AXIS));
         //se añade el componente de video
         VIDEO.add(tphoto.Componente());
         imagen.setText("");
         } catch (Exception e) {
         JOptionPane.showMessageDialog(rootPane, "Error al cargar CAMARA");
         }*/
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelsContainer = new javax.swing.JTabbedPane();
        mainPanel = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        registroPanel = new javax.swing.JPanel();
        photoContainer = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        photoDPI = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        VIDEO = new javax.swing.JPanel();
        imagen = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        nameField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        lastField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        dpiField = new javax.swing.JTextField();
        sexoField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        fechaField = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        uidField = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        accesoPanel = new javax.swing.JPanel();
        showPhoto = new javax.swing.JLabel();
        jLayeredPane4 = new javax.swing.JLayeredPane();
        jLabel13 = new javax.swing.JLabel();
        showNameField = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        showLastField = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        showEntradaField = new javax.swing.JTextField();
        uidTagField = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        configuracionPanel = new javax.swing.JPanel();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        userField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        passField = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        dataBaseField = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        eventCombo = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        servidorField = new javax.swing.JTextField();
        dataBasePanel = new javax.swing.JPanel();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);

        panelsContainer.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);

        mainPanel.setBackground(new java.awt.Color(255, 255, 255));

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/IMG_4605.JPG"))); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        panelsContainer.addTab("Main", mainPanel);

        photoDPI.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        photoDPI.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/defaultUser.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(photoDPI, javax.swing.GroupLayout.DEFAULT_SIZE, 769, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(photoDPI, javax.swing.GroupLayout.PREFERRED_SIZE, 400, Short.MAX_VALUE)
        );

        photoContainer.addTab("DPI", jPanel1);

        VIDEO.setBorder(new javax.swing.border.MatteBorder(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/lead.png")))); // NOI18N
        VIDEO.setPreferredSize(new java.awt.Dimension(320, 240));

        javax.swing.GroupLayout VIDEOLayout = new javax.swing.GroupLayout(VIDEO);
        VIDEO.setLayout(VIDEOLayout);
        VIDEOLayout.setHorizontalGroup(
            VIDEOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 290, Short.MAX_VALUE)
        );
        VIDEOLayout.setVerticalGroup(
            VIDEOLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 210, Short.MAX_VALUE)
        );

        imagen.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        imagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/user (2).png"))); // NOI18N
        imagen.setBorder(new javax.swing.border.MatteBorder(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/lead.png")))); // NOI18N

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/1316233129_Camera.png"))); // NOI18N
        jButton7.setText("Tomar Foto");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/aceptar.png"))); // NOI18N
        jButton8.setText("Aceptar");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(167, 167, 167)
                        .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(VIDEO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                        .addComponent(imagen, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(81, 81, 81))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton7, jButton8});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(VIDEO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(imagen, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(50, 50, 50))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton7, jButton8});

        photoContainer.addTab("Foto", jPanel2);

        jLabel8.setText("Apellido");

        jLabel7.setText("Nombre");

        jLabel9.setText("DPI");

        jLabel10.setText("Sexo");

        jLabel11.setText("Fecha Nacimiento");

        jLabel12.setText("UID Tag");

        uidField.setEditable(false);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/1316233577_folder_search.png"))); // NOI18N
        jButton4.setText("Leer Tag");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/aceptar.png"))); // NOI18N
        jButton5.setText("Guardar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/1316234747_search_b.png"))); // NOI18N
        jButton6.setText("Leer DPI");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jLayeredPane3Layout = new javax.swing.GroupLayout(jLayeredPane3);
        jLayeredPane3.setLayout(jLayeredPane3Layout);
        jLayeredPane3Layout.setHorizontalGroup(
            jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane3Layout.createSequentialGroup()
                .addGap(80, 80, 80)
                .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jLayeredPane3Layout.createSequentialGroup()
                        .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(54, 54, 54)
                        .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(lastField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jLayeredPane3Layout.createSequentialGroup()
                                .addComponent(dpiField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(71, 71, 71)
                                .addComponent(sexoField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jLayeredPane3Layout.createSequentialGroup()
                            .addComponent(fechaField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(uidField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLayeredPane3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lastField, nameField});

        jLayeredPane3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel10, jLabel7, jLabel8, jLabel9});

        jLayeredPane3Layout.setVerticalGroup(
            jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane3Layout.createSequentialGroup()
                .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jLayeredPane3Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lastField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 16, Short.MAX_VALUE)
                        .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane3Layout.createSequentialGroup()
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(dpiField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane3Layout.createSequentialGroup()
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(sexoField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jLayeredPane3Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jLayeredPane3Layout.createSequentialGroup()
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                        .addComponent(fechaField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane3Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jLayeredPane3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jLayeredPane3Layout.createSequentialGroup()
                                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(uidField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18))))
        );

        jLayeredPane3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {lastField, nameField});

        jLayeredPane3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel10, jLabel7, jLabel8, jLabel9});

        jLayeredPane3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton4, jButton5, jButton6});

        jLayeredPane3.setLayer(nameField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jLabel8, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(lastField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jLabel7, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jLabel9, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(dpiField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(sexoField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jLabel10, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jLabel11, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(fechaField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jLabel12, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(uidField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jButton4, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jButton5, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane3.setLayer(jButton6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout registroPanelLayout = new javax.swing.GroupLayout(registroPanel);
        registroPanel.setLayout(registroPanelLayout);
        registroPanelLayout.setHorizontalGroup(
            registroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane3, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(registroPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(photoContainer))
        );
        registroPanelLayout.setVerticalGroup(
            registroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(registroPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(photoContainer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
        );

        panelsContainer.addTab("Registro", registroPanel);

        showPhoto.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        showPhoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/defaultUser.jpg"))); // NOI18N

        jLabel13.setText("Nombre :");

        showNameField.setEditable(false);

        jLabel16.setText("Apellido :");

        showLastField.setEditable(false);

        jLabel17.setText("Entrada : ");

        showEntradaField.setEditable(false);

        uidTagField.setEditable(false);

        jLabel18.setText("UID TAG ");

        javax.swing.GroupLayout jLayeredPane4Layout = new javax.swing.GroupLayout(jLayeredPane4);
        jLayeredPane4.setLayout(jLayeredPane4Layout);
        jLayeredPane4Layout.setHorizontalGroup(
            jLayeredPane4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jLayeredPane4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(showNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(showLastField, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(showEntradaField, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uidTagField, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jLayeredPane4Layout.setVerticalGroup(
            jLayeredPane4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane4Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(showNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(showLastField, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(showEntradaField, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(uidTagField, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );
        jLayeredPane4.setLayer(jLabel13, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane4.setLayer(showNameField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane4.setLayer(jLabel16, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane4.setLayer(showLastField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane4.setLayer(jLabel17, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane4.setLayer(showEntradaField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane4.setLayer(uidTagField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane4.setLayer(jLabel18, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/headLogo.JPG"))); // NOI18N

        jLabel15.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
        jLabel15.setText("Evento : Spark");
        jLabel15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel15MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout accesoPanelLayout = new javax.swing.GroupLayout(accesoPanel);
        accesoPanel.setLayout(accesoPanelLayout);
        accesoPanelLayout.setHorizontalGroup(
            accesoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(accesoPanelLayout.createSequentialGroup()
                .addComponent(showPhoto, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane4))
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        accesoPanelLayout.setVerticalGroup(
            accesoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(accesoPanelLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(accesoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(accesoPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(showPhoto, javax.swing.GroupLayout.DEFAULT_SIZE, 685, Short.MAX_VALUE))
                    .addGroup(accesoPanelLayout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jLayeredPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        panelsContainer.addTab("Acceso", accesoPanel);

        jLabel1.setText("Usuario");

        jLabel2.setText("Contraseña");

        jLabel3.setText("Base de Datos");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/aceptar.png"))); // NOI18N
        jButton1.setText("Guardar ");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        eventCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel4.setText("Evento");

        jLabel5.setText("Servidor");

        javax.swing.GroupLayout jLayeredPane1Layout = new javax.swing.GroupLayout(jLayeredPane1);
        jLayeredPane1.setLayout(jLayeredPane1Layout);
        jLayeredPane1Layout.setHorizontalGroup(
            jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jLayeredPane1Layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 228, Short.MAX_VALUE)
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(eventCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jLayeredPane1Layout.createSequentialGroup()
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jLayeredPane1Layout.createSequentialGroup()
                        .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(dataBaseField, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jLayeredPane1Layout.createSequentialGroup()
                                    .addGap(18, 18, 18)
                                    .addComponent(servidorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(passField, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(userField, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jLayeredPane1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {dataBaseField, servidorField});

        jLayeredPane1Layout.setVerticalGroup(
            jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLayeredPane1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(userField, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(eventCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(passField, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dataBaseField, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLayeredPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(servidorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 23, Short.MAX_VALUE))
        );

        jLayeredPane1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {dataBaseField, servidorField});

        jLayeredPane1.setLayer(userField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(passField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(dataBaseField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(eventCombo, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane1.setLayer(servidorField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout configuracionPanelLayout = new javax.swing.GroupLayout(configuracionPanel);
        configuracionPanel.setLayout(configuracionPanelLayout);
        configuracionPanelLayout.setHorizontalGroup(
            configuracionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(configuracionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(162, Short.MAX_VALUE))
        );
        configuracionPanelLayout.setVerticalGroup(
            configuracionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(configuracionPanelLayout.createSequentialGroup()
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 413, Short.MAX_VALUE))
        );

        panelsContainer.addTab("Configuración", configuracionPanel);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/1389964910_Time-Machine.png"))); // NOI18N
        jButton2.setText("Cargar base de datos");
        jButton2.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zeroticket/Images/1389965068_Downloads.png"))); // NOI18N
        jButton3.setText("Guardar Base de datos");
        jButton3.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jLayeredPane2Layout = new javax.swing.GroupLayout(jLayeredPane2);
        jLayeredPane2.setLayout(jLayeredPane2Layout);
        jLayeredPane2Layout.setHorizontalGroup(
            jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane2Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28))
        );
        jLayeredPane2Layout.setVerticalGroup(
            jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLayeredPane2Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jLayeredPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        jLayeredPane2.setLayer(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jLayeredPane2.setLayer(jButton3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout dataBasePanelLayout = new javax.swing.GroupLayout(dataBasePanel);
        dataBasePanel.setLayout(dataBasePanelLayout);
        dataBasePanelLayout.setHorizontalGroup(
            dataBasePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dataBasePanelLayout.createSequentialGroup()
                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 245, Short.MAX_VALUE))
        );
        dataBasePanelLayout.setVerticalGroup(
            dataBasePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dataBasePanelLayout.createSequentialGroup()
                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 517, Short.MAX_VALUE))
        );

        panelsContainer.addTab("Copias de Seguridad", dataBasePanel);

        jMenu1.setText("Zero Innovation");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Main");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Registro");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Acceso");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Configuración");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("Copias de Seguridad");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setText("Salir");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem6);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelsContainer, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelsContainer)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void eventList() {

        try {

            st = (Statement) connection.createStatement();
            resultSet = st.executeQuery("SELECT nombre, lugar, fecha, idEvent FROM Event ORDER BY Nombre");
            ResultSetMetaData metaData = (ResultSetMetaData) resultSet.getMetaData();

            resultSet.last();                // estas lineas se mueven al final de la consulta 

            int numrows = resultSet.getRow();
            int numcolumn = metaData.getColumnCount();

            dataEventList = new Event[numrows];  //la cantidad de material que va a salir 

            resultSet.beforeFirst();

            int pos = 0;
            while (resultSet.next()) {
                String nom = "";
                int cod = 0;
                String lug = "";
                String date = "";

                for (int i = 0; i <= numcolumn; i++) {
                    switch (i) {
                        case 1:
                            nom = resultSet.getString(1);
                            break;
                        case 4:
                            cod = resultSet.getInt(4);
                            break;
                        case 3:
                            date = resultSet.getString(3);
                            break;
                        case 2:
                            lug = resultSet.getString(2);

                    }
                }

                dataEventList[pos] = new Event(nom, lug, date, cod);
                pos++;
            }

            eventCombo.removeAllItems();  // limpio el comboBox

            for (int i = 0; i <= dataEventList.length - 1; i++) {
                eventCombo.addItem("" + dataEventList[i].getNombre() + " / " + dataEventList[i].getLugar() + " / " + dataEventList[i].getFecha());
            }

        } catch (SQLException ex) {
            Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
        }

        AutoCompleteDecorator.decorate(eventCombo);
        eventCombo.setSelectedIndex(0);

    }

    private class Event {

        private String nombre;
        private String lugar;
        private String fecha;
        private int code;

        public Event(String nombre, String lugar, String fecha, int code) {
            this.nombre = nombre;
            this.lugar = lugar;
            this.fecha = fecha;
            this.code = code;
        }

        public int getCode() {
            return code;
        }

        public String getNombre() {
            return nombre;
        }

        public String getLugar() {
            return lugar;
        }

        public String getFecha() {
            return fecha;
        }

    }
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        panelsContainer.removeAll();
        panelsContainer.add(mainPanel);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        panelsContainer.removeAll();
        panelsContainer.add(registroPanel);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        panelsContainer.removeAll();
        panelsContainer.add(accesoPanel);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        panelsContainer.removeAll();
        panelsContainer.add(configuracionPanel);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        // End program 
        System.exit(0); // Sale sin errores 
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        saveFile();
        // Pruebo si los datos que metio conecta con una base de datos. 
        if (DataBaseClass.connect(ConfigClass.configReaderInit())) {
            // Cargar Backup 

            MainView mv = new MainView();
            mv.setExtendedState(6);
            mv.setLocationRelativeTo(null);
            mv.setVisible(true);

        } else {
            passField.setText("");
            JOptionPane.showMessageDialog(null, "Error en conectarse a la base de datos", "Las credenciales de la base de datos no son las correctas, porfavor intentelo de nuevo", 0);

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        panelsContainer.removeAll();
        panelsContainer.add(dataBasePanel);
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // Crear Backup
        DataBaseClass.commitBackup(ConfigClass.configReader());
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // Cargar Backup 
        DataBaseClass.updateBackup(ConfigClass.configReaderInit(), System.getProperty("user.dir") + "" + File.separator + "src" + File.separator + "DataBase" + File.separator + "dataBackup.sql");

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // Primero conecto el lector de NFC 
        SmartCardTerminal.connectNFCReader();// Listo para empezar la aplicacion 

        CardTerminal terminal = null;
        if (SmartCardTerminal.getTerminal() != null) {  // Si aun existe coneccion, pues continuo, 
            terminal = SmartCardTerminal.getTerminal();
            // Tengo el terminal, puedo empezar a leer. 
            String data[] = readUID(terminal);

            if (data[2].equalsIgnoreCase("9000")) {
                uidField.setText(data[0]);

            } else {
                JOptionPane.showMessageDialog(rootPane, "No se pudo leer la información", "Error en lectura", 0);
            }
            // solo para asegurarme que esta desconectado 
            //SmartCardTerminal.setTerminal(null);
        } else {
            // Vuelvo a conectarme 
            //SmartCardTerminal.connectNFCReader();
            // Repito este procedimiento 

        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // Primero connecto el lector de DPI
        SmartCardTerminal.connectDPIReader();
        DPIReader ccr = new DPIReader();

        CardTerminal terminal = null;
        if (SmartCardTerminal.getTerminal() != null) {
            terminal = SmartCardTerminal.getTerminal();

            try {

                ccr.doCardReaderCommunication(terminal);
                info = ccr.getDPI();
                dpiField.setText(info.getDpi());
                nameField.setText(info.getPrimerNombre().replace("  ", "") + " " + info.getSegundoNombre().replace("  ", ""));
                lastField.setText(info.getPrimerApellido().replace("  ", "") + " " + info.getSegundoApellido().replace("  ", ""));
                sexoField.setText(info.getSexo());
                fechaField.setText(info.getNacimiento());
                // Sino esta en el tabl de dpi, entonces lo obligare a estar. 
                photoContainer.setSelectedIndex(0);
                photoDPI.setIcon(setPhotoID(info.getPhotoOnBytes()));// Coloco la foto

                // Voy a desconectar el lector 
                ccr.setCardTerminal(null);
                // solo para asegurarme que esta desconectado 
                //SmartCardTerminal.setTerminal(null);

            } catch (DPIParseException ex) {

                System.err.println("Error en leer el dpi " + ex);

            }

        } else {
            // Si esta null, intento conectarme otra vez. 
            SmartCardTerminal.connectDPIReader();
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        tphoto.capturarImagen();
        preview();

    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        if (tphoto.getImagen() != null) {

            tphoto.turnOff();

        }
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

        tagID = -1;
        userID = -1;
        // At first, is the tag in the system ? 
        Object data[] = new DataBaseClass().giveData("SELECT idTag FROM tag WHERE UID like '" + uidField.getText() + "';");
        if (data[0] != null) {
            tagID = Integer.parseInt(data[0].toString());
            DataBaseClass.executeQuery("DELETE FROM tag_user where tagid = " + tagID);

        } else {
            // No existe, es nuevo el tag, entonces lo ingresare. 
            int resultado = 0;

            try {

                PreparedStatement ps = null;
                ps = (PreparedStatement) connection.prepareStatement("INSERT INTO TAG (UID,Estado) values (?,?) ", PreparedStatement.RETURN_GENERATED_KEYS);

                // UID
                ps.setString(1, uidField.getText());

                //Estado 
                ps.setString(2, "Activo");

                resultado = ps.executeUpdate();

                resultSet = ps.getGeneratedKeys();
                while (resultSet.next()) {
                    tagID = resultSet.getInt(1);  // Aqui termina mi metodo con exito. 
                }

            } catch (SQLException e) {
                tagID = -1;
                JOptionPane.showMessageDialog(rootPane, "Error al ingresar Tag   " + e, "Error al Ingreso de datos", 0);

            } // fin del catch
        }

        // Si el Tag no es -1, entonces ingresare a la persona. 
        if (tagID != -1) {
            int resultado = 0;

            try {

                PreparedStatement ps = null;
                ps = (PreparedStatement) connection.prepareStatement("INSERT INTO USER (Nombre,Apellido, Fecha_nacimiento, Foto, DPI, Sexo ) values (?,?,?,?,?,?) ", PreparedStatement.RETURN_GENERATED_KEYS);

                // Nombre
                ps.setString(1, nameField.getText());

                //Apellido 
                ps.setString(2, lastField.getText());

                //Nacimiento 
                ps.setString(3, fechaField.getText());

                //Fotos de bytes 
                ps.setBinaryStream(4, new ByteArrayInputStream(info.getPhotoOnBytes()));

                ps.setString(5, dpiField.getText());

                ps.setString(6, sexoField.getText());

                resultado = ps.executeUpdate();

                resultSet = ps.getGeneratedKeys();
                while (resultSet.next()) {
                    userID = resultSet.getInt(1);  // Aqui termina mi metodo con exito. 
                }

            } catch (SQLException e) {
                userID = -1;
                JOptionPane.showMessageDialog(rootPane, "Error al ingresar Usuario   " + e, "Error al Ingreso de datos", 0);

            } // fin del catch
        }

        // Si no hay errores en user y tag, bueno lo relacionare 
        if (userID != -1 && tagID != -1) {
            DataBaseClass.executeQuery("INSERT INTO tag_user (UserId,Tagid) values (" + userID + "," + tagID + ")");
            // Vamos a ingresar al evento 
            DataBaseClass.executeQuery("INSERT INTO event_user (UserId,Eventoid) values (" + userID + ",1)");

            JOptionPane.showMessageDialog(null, "Ya eres parte de Zero Ticket \n"
                    + "Nombre : " + nameField.getText() + "\n"
                    + "Apellido : " + lastField.getText() + "\n"
                    + "Fecha Nacimiento : " + fechaField.getText() + "\n"
                    + "TAG UID : " + uidField.getText(), "Bienvenido a Zero Ticket", 1, new ImageIcon(info.getPhotoOnBytes()));

            blankSignUp();
        }


    }//GEN-LAST:event_jButton5ActionPerformed
    private void blankSignUp() {
        nameField.setText("");
        lastField.setText("");
        uidField.setText("");
        fechaField.setText("");
        sexoField.setText("");
        uidField.setText("");
    }

    private void jLabel15MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel15MouseClicked

        able = true;
        new assistCicle();


    }//GEN-LAST:event_jLabel15MouseClicked
    private void showEntry(String uid) {
        int eventUserId = -1;
        Object data[] = new DataBaseClass().giveData("SELECT idEvent_User, User.Nombre, User.Apellido, User.foto FROM tag, tag_user, event_user INNER JOIN user ON event_user.userid = user.idUser WHERE eventoid = 1 AND tag.UID like '" + uid + "' AND user.idUser = tag_user.userid ;");
        if (data[0] != null) {

            eventUserId = Integer.parseInt(data[0].toString());
            showNameField.setText(data[1].toString());
            showLastField.setText(data[2].toString());
            showEntradaField.setText("Pase adelante ");
            // FOTO 
            byte[] bits = null;
            bits = (byte[]) data[3];

            ImageIcon imagef;

            if (bits != null) {
                imagef = new ImageIcon(bits);
            } else {
                imagef = new ImageIcon(System.getProperty("user.dir") + "" + File.separator + "src" + File.separator + "zeroticket" + File.separator + "Images" + File.separator + "defaultUser.jpg");
            }

            showPhoto.setIcon(imagef);

        } else {
            // No puede entrar 
            eventUserId = -1;
            showNameField.setText("NO NAME ");
            showLastField.setText("NO LAST NAME ");
            showEntradaField.setText(" - ");
            ImageIcon imagef;

            imagef = new ImageIcon(System.getProperty("user.dir") + "" + File.separator + "src" + File.separator + "zeroticket" + File.separator + "Images" + File.separator + "defaultUser.jpg");
            showPhoto.setIcon(imagef);

        }

    }

    class assistCicle implements Runnable {

        Thread readUser = null;

        public assistCicle() {
            readUser = new Thread(this);
            readUser.start();
        }

        @Override
        public void run() {
            while (true) {
                System.out.println("Estoy en el ciclo ");
                if (able) {
                    able = false; // entre, no me molesten 

                    // Primero conecto el lector de NFC 
                    SmartCardTerminal.connectNFCReader();// Listo para empezar la aplicacion 

                    CardTerminal terminal = null;
                    if (SmartCardTerminal.getTerminal() != null) {  // Si aun existe coneccion, pues continuo, 
                        terminal = SmartCardTerminal.getTerminal();
                        // Tengo el terminal, puedo empezar a leer. 
                        String data[] = readUID(terminal);

                        if (data[2].equalsIgnoreCase("9000")) {

                            uidTagField.setText(data[0].toUpperCase());
                            showEntry(data[0].toUpperCase());

                        } else {

                            //JOptionPane.showMessageDialog(rootPane, "No se pudo leer la información", "Error en lectura", 0);
                            uidTagField.setText("");
                        }
                        // solo para asegurarme que esta desconectado 
                        //SmartCardTerminal.setTerminal(null);
                    } else {

                        uidTagField.setText("");

                    }
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ex) {
                        JOptionPane.showMessageDialog(null, "Error en ciclo Thread");
                    }
                    able = true;
                }
            } // Fin while 

        }

    }

    public void preview() {

        ImageIcon im = new ImageIcon(tphoto.getImagen()); // obtengo la imagen. 
        // creare una condicion cuando la imagen sea demasiado grande

        if (im.getIconWidth() > 158 || im.getIconHeight() > 158) {
            ImageIcon imaescala = new ImageIcon(im.getImage().getScaledInstance(158, 158, 100));
            imagen.setIcon(imaescala);
        } else {
            imagen.setIcon(im);
        }

    }
    /* 
     Este metodo solo es estetico y es para que la foto 
     no quede distorcionada, por lo que se usa para darle un formato adecuado 
     de 500 por 667 pixeles 
     */

    private ImageIcon setPhotoID(byte[] bytesPhoto) {
        BufferedImage imag = null;
        try {
            imag = ImageIO.read(new ByteArrayInputStream(bytesPhoto));
        } catch (IOException ex) {

            JOptionPane.showMessageDialog(rootPane, "Error en transformación de foto : " + ex, "Error en transformación de foto", 0);

        }
        int altoLabel = photoDPI.getHeight();
        int anchophoto = (int) ((int) altoLabel * 1);
        BufferedImage rescaled = Scalr.resize(imag, Scalr.Method.SPEED, Scalr.Mode.FIT_EXACT, anchophoto, altoLabel, Scalr.OP_ANTIALIAS);  // the actual rescale

        //BufferedImage rescaled = Scalr.resize(imag, Scalr.Method.SPEED, Scalr.Mode.FIT_EXACT, 500, 667, Scalr.OP_ANTIALIAS);  // the actual rescale
        //BufferedImage finale = Scalr.crop(rescaled, 0, 30, 400, 400, Scalr.OP_ANTIALIAS);
        return new ImageIcon(rescaled);
    }

    private String[] readUID(CardTerminal terminal) {

        String data = "";
        String UID = "";
        String status = "";

        try {
            // Connect wit hthe card
            Card card = terminal.connect("*");

            System.out.println("Card: " + card);
            CardChannel channel = card.getBasicChannel();

            card.getATR().getBytes();

            byte[] baReadUID = new byte[]{(byte) 0xFF, (byte) 0xCA, (byte) 0x00,
                (byte) 0x00, (byte) 0x00};

            if (send(baReadUID, channel)[1].equalsIgnoreCase("9000")) {

                UID = send(baReadUID, channel)[0].toUpperCase();
                System.out.println("UID: " + UID);
                status = "9000";

            }

            // Disconnect the card
            card.disconnect(false);

        } catch (CardException ex) {

            //JOptionPane.showMessageDialog(rootPane, "Error en lectura " + ex, "Error en lectura", 0);
        }

        return new String[]{UID, data, status};

    }

    // Read Chip 
    private String[] send(byte[] cmd, CardChannel channel) {

        String res = "";

        byte[] baResp = new byte[258];
        ByteBuffer bufCmd = ByteBuffer.wrap(cmd);
        ByteBuffer bufResp = ByteBuffer.wrap(baResp);

        // output = The length of the received response APDU
        int output = 0;

        try {

            output = channel.transmit(bufCmd, bufResp);

        } catch (CardException ex) {
            ex.printStackTrace();
        }

        for (int i = 0; i < output; i++) {
            //res += String.format("%02X", baResp[i]); // En bytes // The result is formatted as a hexadecimal integer
            res += String.format("%02x", baResp[i]); // String

        }

        if (res.length() != 4) // Divido mensaje, del estado del mensaje. 
        {
            return new String[]{res.substring(0, res.length() - 4), res.substring(res.length() - 4, res.length())};
        } else {
            return new String[]{"", res}; // No hay datos solo estado
        }        //return res;
    }

    // UTILS 
    private String toStringFromHex(String hex) {
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < hex.length(); i += 2) {
            String str = hex.substring(i, i + 2);
            output.append((char) Integer.parseInt(str, 16));
        }
        return output.toString();

    }

    private void saveFile() {
        FileWriter fileToSave = null;

        try {
            fileToSave = new FileWriter(System.getProperty("user.dir") + "" + File.separator + "src" + File.separator + "Configuracion" + File.separator + "config.txt");
            PrintWriter pw = new PrintWriter(fileToSave);
            pw.println(servidorField.getText());
            pw.println(userField.getText());
            pw.println(passField.getText());
            pw.println(dataBaseField.getText());

        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "Error en archivo config.txt ", "Error al crear archivo" + ex, 0);

        } finally {
            try {
                if (null != fileToSave) {
                    fileToSave.close();
                }

            } catch (Exception E2) {
                JOptionPane.showMessageDialog(null, "Error en archivo config.txt ", "Error al crear archivo" + E2, 0);

            }
        }

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel VIDEO;
    private javax.swing.JPanel accesoPanel;
    private javax.swing.JPanel configuracionPanel;
    private javax.swing.JPasswordField dataBaseField;
    private javax.swing.JPanel dataBasePanel;
    private javax.swing.JTextField dpiField;
    private javax.swing.JComboBox eventCombo;
    private javax.swing.JTextField fechaField;
    private javax.swing.JLabel imagen;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JLayeredPane jLayeredPane4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField lastField;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTextField nameField;
    private javax.swing.JTabbedPane panelsContainer;
    private javax.swing.JPasswordField passField;
    private javax.swing.JTabbedPane photoContainer;
    private javax.swing.JLabel photoDPI;
    private javax.swing.JPanel registroPanel;
    private javax.swing.JTextField servidorField;
    private javax.swing.JTextField sexoField;
    private javax.swing.JTextField showEntradaField;
    private javax.swing.JTextField showLastField;
    private javax.swing.JTextField showNameField;
    private javax.swing.JLabel showPhoto;
    private javax.swing.JTextField uidField;
    private javax.swing.JTextField uidTagField;
    private javax.swing.JTextField userField;
    // End of variables declaration//GEN-END:variables
}
